import Box2D.b2 as b2
import pyglet
from pyglet.image import Animation, AnimationFrame

import activations
from camera import pixels_to_world
from debug import msg
import entity
import resources


class Goal(entity.StaticSprite):
    def __init__(self, mode, start_configurations):

        # The relative position of the image anchor. (0.5, 0.5) gives
        # a centralized anchorpoint.
        # Here: lower right corner.
        self.anchor = (0.5, 0)

        # Import images
        self.images = []
        self.images.append(resources.image("data/img/goal.png",
                                           self.anchor))
        
        # So that the player knows when he can exit
        ((x, y), self.rotation) = start_configurations

        # # Create a dictionary with animations.
        # self.animations = {"close": Animation([AnimationFrame(self.images[1],
        #                                                       0.05),
        #                                       AnimationFrame(self.images[0],
        #                                                      None)]),
        #                    "open": Animation([AnimationFrame(self.images[1],
        #                                                      0.05),
        #                                        AnimationFrame(self.images[2],
        #                                                       None)]),
        #                    }

        ((x, y), rot) = start_configurations

        super(Goal, self).__init__(
            mode, self.images[0], anchor=self.anchor,
            x=x, y=y, rot=rot,
            e_type="goal")

        # self.activated = False
        # self.activate_counter = 0

        self.fixture.sensor = True

    def interact(self):
        """
        Called when player interacts with object.
        """
        self.mode.end_level(success=True)

    def update(self, dt):
        super(Goal, self).update(dt)
